package com.xishu.shard;

import io.shardingjdbc.core.api.algorithm.sharding.PreciseShardingValue;
import io.shardingjdbc.core.api.algorithm.sharding.standard.PreciseShardingAlgorithm;

import java.util.Collection;

/**
 * 分表策略
 */
public class TableSharding implements PreciseShardingAlgorithm<Long> {

    @Override
    public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<Long> shardingValue) {
        ShardUtil shardUtil = ShardUtil.getInstance();


        //在单数据库里面的第几张表
        long index = shardingValue.getValue() / shardUtil.getDbMap().size();
        return "order" + index;
    }
}
